#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#pragma warning
using namespace std;
void InputMatrix(int d1, int d2, int* matrix)
{
   cout << "Please input the elements of the matrix:" << endl;
   for (int i = 0; i < d1 * d2; i++)
   {
       cin >> matrix[i];
   }
   cout << "---------------------------------------------------------" << endl;
}
void OutputMatrix(int d1, int d2, int* matrix)
{
   cout << "The original matrix you input is:" << endl;
   for (int i = 0; i < d1 * d2; i++)
   {
       cout << matrix[i] << "    ";
       if ((i + 1) % d1 == 0)
           cout << endl;
   }
   cout << "---------------------------------------------------------" << endl;
}
void RotateMatrix(int d1, int d2, int* matrix) 
{
   int i, j, angle;  
   char flag = 'y';
   while (tolower(flag) == 'y') 
   {
       cout << "Please input the angle you want to rotate(90, 180 or 270): ";
       cin >> angle;
       switch (angle)
       {
       case 90:
           cout << "The matrix after rotating 180 is:" << endl;
           for (i = d1 * (d2 - 1); i <= d1 * d2 - 1; i++)
           {
               for (j = i; j >= 0; j -= d1)
               {
                   cout << matrix[j] << "    ";
               }
               cout << endl;
           }
           break;
       case 180:
           cout << "The matrix after rotating 180 is:" << endl;
           for (i = d1 * d2 - 1; i >= 0; j -= 3)
           {
               for (j = 0; j < d1; j++)
               {
                   cout << matrix[i - j] << "    ";
               }
               cout << endl;
           }
           break;
       case 270:
           cout << "The matrix after rotating 270 is:" << endl;
           for (i = d1 - 1; i >= 0; i--)
           {
               for (j = 0; j < d2; j++)
               {
                   cout << matrix[i + d1 * j] << "    ";
               }
               cout << endl;
           }
           break;
       default:
           cout << "You input a wrong angle!" << endl;
           break;
       }
       cout << "--------------------------------------------------------------" << endl;
       cout << "Do you want to continue to rotate the matrix?(Y/N)";
       cin >> flag;
   }
}
void main() 
{
   int i, d1, d2;
   int* matrix;
   matrix = new int[100];
   cout << "Please input two dimensions of the matrix: ";
   cin >> d1 >> d2;
   InputMatrix(d1, d2, matrix);
   OutputMatrix(d1, d2, matrix);
   RotateMatrix(d1, d2, matrix);
   delete[]matrix;
}